﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace zk312.UI.Controllers
{
    [Route("api/[controller][action]")]
    [ApiController]
    public class fileController : ControllerBase
    {

        [HttpPost]
        public IActionResult UpLoadFile()
        {
            try
            {
                string fpath = "";

                var imgFile = Request.Form.Files;

                foreach (var item in imgFile)
                {
                    string filePath = Directory.GetCurrentDirectory() + "/Pic/" + item.FileName;

                    using (FileStream fs = new FileStream(filePath, FileMode.Create))
                    {
                        item.CopyTo(fs);
                    }
                    fpath = "https://localhost:7253/Pic/" + item.FileName;
                }
                return Ok(fpath);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
